package com.sds.shop.action;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sds.fw.mvc.Action;
import com.sds.fw.mvc.HttpUtil;
import com.sds.shop.dao.CategoryDAO;
import com.sds.shop.dao.ProductDAO;
import com.sds.shop.vo.CategoryVO;

public class ProductInsertFormAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		ProductDAO dao=ProductDAO.getInstance();
		CategoryDAO cdao=CategoryDAO.getInstance();
		String maxPrdId=dao.getMaxPrdId();
		String newPrdId="PRD";
		System.out.println(maxPrdId);
		maxPrdId=maxPrdId.substring(3);
		int prdnum=Integer.parseInt(maxPrdId);
		prdnum++;
		maxPrdId=Integer.toString(prdnum);
		for(int i = 0; i < 9-maxPrdId.length();i++){
			newPrdId=newPrdId+"0";
		}
		newPrdId=newPrdId+maxPrdId;
		request.setAttribute("newprdid", newPrdId);
		
		ArrayList<CategoryVO> catevo=cdao.getCategoryList();
		
		request.setAttribute("catelist", catevo);
		HttpUtil.forward(request, response, "/jsp/productinsert.jsp");

	}

}
